package tgc.edu.ljc.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tgc.edu.ljc.dao.UserRepository;
import tgc.edu.ljc.entity.TbUser;

@Service
public class UserService {
	@Autowired
	private UserRepository userDAO;
	
	public List<TbUser> findAll(){
		return userDAO.findAll();
	}
	
	public TbUser findById(Integer id) {
		Optional<TbUser> optional = userDAO.findById(id);
		if(optional.isPresent()) {
			return optional.get();
		}
		return null;
	}
	
	public void save(TbUser model) {
		userDAO.save(model);
	}
	
	public void delete(Integer id) {
		userDAO.deleteById(id);
	}
	
	public void delete(TbUser model) {
		userDAO.delete(model);
	}
	
	public List<TbUser> findBySex(String sex){
		return userDAO.findBySex(sex);
	}
}
